package com.example.oneSpringMVC.controller;


import com.example.oneSpringMVC.common.PageResult;
import com.example.oneSpringMVC.common.Result;
import com.example.oneSpringMVC.entity.Permission;
import com.example.oneSpringMVC.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xinTong
 * @since 2024-01-24
 */
@RestController
@RequestMapping("api/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 查询全部数据
     * @return
     */
    @GetMapping("listAll")
    public Result listAll(){

        List<Permission> list = permissionService.listAll();
        return Result.success(list);
    }

    /**
     * 分页查询数据
     * @param pageQuery
     * @return
     */
    @GetMapping("list")
    public Result list(@RequestParam(value = "pageNum")int pageNum,
                       @RequestParam(value = "pageSize")int pageSize){
        PageResult result = permissionService.list(pageNum, pageSize);
        return Result.success(result);
    }

    /**
     * 加载方法标识权限信息到数据库
     * @return
     */
    @PostMapping("load")
    public Result load(){
        //TODO: 未知信息
        return Result.success();
    }

    /**
     * 通过角色id获取相应的权限信息
     * @param roleId
     * @return
     */
    @GetMapping("queryPermission/{roleId}")
    public Result queryPermission(@PathVariable Long roleId){
        List<Permission> list = permissionService.queryPermission(roleId);
        return Result.success(list);
    }
}
